home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / ccd0605.iso / Software / Freeware / Programare / highlight / highlight-W32GUI-2.2-10b-Setup.exe / {app} / src / stringtools.cpp < prev    next >
C/C++ Source or Header  |  2005-03-31  |  2KB  |  92 lines

  1. /***************************************************************************
  2.                           stringtools.cpp  -  description
  3.                              -------------------
  4.     begin                : Mon Dec 10 2001
  5.     copyright            : (C) 2001 by AndrΘ Simon
  6.     email                : andre.simon1@gmx.de
  7.  ***************************************************************************/
  8.  
  9. /***************************************************************************
  10.  *                                                                         *
  11.  *   This program is free software; you can redistribute it and/or modify  *
  12.  *   it under the terms of the GNU General Public License as published by  *
  13.  *   the Free Software Foundation; either version 2 of the License, or     *
  14.  *   (at your option) any later version.                                   *
  15.  *                                                                         *
  16.  ***************************************************************************/
  17.  
  18. #include "stringtools.h"
  19.  
  20. #include <sstream>
  21. #include <iostream>
  22. #include <cctype>
  23.  
  24. using namespace std;
  25.  
  26. namespace StringTools
  27.   {
  28. // Make a lowercase copy of s:
  29. // (C) Bruce Eckel, Thinking in C++ Vol 2
  30.  
  31. string lowerCase(const string& s)
  32. {
  33.   char* buf = new char[s.length()];
  34.   s.copy(buf, s.length());
  35.   for(unsigned int i = 0; i < s.length(); i++)
  36.     buf[i] = tolower(buf[i]);
  37.   string r(buf, s.length());
  38.   delete buf;
  39.   return r;
  40. }
  41.  
  42. int str2int(string s)
  43. {
  44.   istringstream os(s);
  45.   int intVal;
  46.   os >> intVal;
  47.   return intVal;
  48. }
  49.  
  50.  bool isAlpha(unsigned char c)
  51.  {
  52.    return (isalpha(c) || c == '_');
  53.  }
  54.  
  55. string trimRight(const string &value)
  56.  {
  57.   string::size_type where = value.find_last_not_of(" \t\r");
  58.  
  59.   if (where == string::npos)
  60.    // string has nothing but space
  61.    return string();
  62.  
  63.   if (where == (value.length() - 1))
  64.    // string has no trailing space, don't copy its contents
  65.    return value;
  66.  
  67.   return value.substr(0, where + 1);
  68.  }
  69.  
  70. unsigned char getNextNonWs(const string &line, int index)
  71. {
  72.   unsigned char c;
  73.   do
  74.     {
  75.       c=line[index++];
  76.     }
  77.   while (isspace(c));
  78.   return c;
  79. }
  80.  
  81. string getParantheseVal(const string &s){
  82.   string::size_type openPos=s.find('(');
  83.   string::size_type closePos=s.rfind(')');
  84.   if (openPos ==string::npos || closePos==string::npos){
  85.     return string();
  86.   }
  87.   return s.substr(openPos+1, closePos-openPos-1);
  88.  
  89. }
  90.  
  91. }
  92.